//https://leetcode.cn/problems/two-sum/submissions/
package codeRandomThoughts.Test1两数之和;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Solution {
    /**
     * 主要是考察检测哈希表和往里面添加值的顺序
     * @param nums
     * @param target
     * @return
     */
    public int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> hashMap = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (hashMap.containsKey(target-nums[i])){
                return new int[]{i,hashMap.get(target-nums[i])};
            }
            hashMap.put(nums[i], i);
        }
        return null;
    }
}
